#!/bin/bash
set -euo pipefail
BaseDir=$(cd "$(dirname "$0")"; pwd)
cd ${BaseDir}

op=${1:-}

conda=C:/tool/miniconda3/Scripts/conda

case $op in
# 激活命令行conda
cmd)
# https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe
cmd.exe "//K" C:/tool/miniconda3/Scripts/activate.bat C:/tool/miniconda3/
;;

# conda的国内镜像源
config)
    cp ./.condarc $HOME/.condarc
    $conda config --show-sources
    echo "清除索引缓存，保证用的是镜像站提供的索引"
    $conda clean -i -y
;;
show)
    $conda config --show
    $conda config --show-sources
    #C:/tool/miniconda3/Scripts/conda config --set show_channel_urls yes
;;

#
versions)
    echo "显示python的可用版本"
    $conda search python
;;
env)
    $conda env list
:<<EOF
./conda.sh env
# conda environments:
#
py312                    C:\Users\homelap\.conda\envs\py312
base                     C:\tool\miniconda3
EOF
;;
py312)
    # C:/tool/miniconda3/Scripts/conda create -h
    $conda create -y --name py312 python=3.12.2
;;

# 因为conda源有时候一些包可能不太好装，此时可以用pip进行安装，所以我们要配置pypi源
pip)
    echo "$APPDATA"
    # pip config set global.index-url --site https://pypi.tuna.tsinghua.edu.cn/simple
    # pip install tqdm -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
    mkdir -p "$APPDATA/pip"
    cp -f ./pip.ini "$APPDATA/pip/."
    echo "配置pip源"
    $conda run pip config list
;;

flask)
    echo "conda base 是否可以安装包..."
    # $conda config --remove channels https://repo.anaconda.com
    $conda install flask -y
;;
esac